<!-- 右边部分 -->
<div class="content">

    <ul class="breadcrumb">
        <li><a href="index.php">首页</a> <span class="divider">/</span></li>
        <li class="active"></li>
    </ul>
    <div class="copyrights">Collect from <a href="http://www.cssmoban.com/" title="网站模板">网站模板</a></div>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="btn-toolbar">
                <div class="btn-group">
                </div>
            </div>
            <div class="well">
                <table class="table">
                    <thead>
                    <tr>
                        <th>图书编号</th>
                        <th>图书名称</th>
                        <th>出版社</th>
                        <th>价格</th>
                        <th>借阅状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php
                    //连接数据库
                    if (empty($_GET['page']))
                        $_GET['page'] = 1;
                    //当前页码
                    $page = (int)$_GET['page'];
                    //6条数据
                    $number = 10;
                    //第几页
                    $index = ($page - 1) * $number;
                    //总页数
                    $total = 1;
                    try {
                        $db = new PDO('mysql:dbname=books;host=127.0.0.1','root','123456');
                        $statement = $db->prepare('select count(*) from book');
                        if ($statement->execute() === false)
                            throw new PDOException('语句执行失败！');
                        $count = (int)$statement->fetch()[0];

                        $total = $count / $number;
                        $total = ceil($total);

                        $statement = $db->prepare('select * from book limit '. $index . ',' . $number);
                        if ($statement->execute() === false)
                            throw new PDOException('语句执行失败2！');
                        $re = (int)$statement->fetchAll();

                        $result= $db->query('select * from book limit '. $index . ',' . $number);
                        $re=$result->fetchAll();
                        if($re){
                            foreach($re as $list){?>
                                <tr class="shuju">
                                    <td><?="$list[bookid]"; ?></td>
                                    <td><?="$list[bookName]"; ?></td>
                                    <td><?="$list[press]";?></td>
                                    <td><?="$list[price]";?></td>
                                    <td><?php
                                        if("$list[status]" ==1){
                                            echo "<span>已借阅</span>";
                                        }else{
                                            echo "<span>未借阅</span>";
                                        }
                                        ?>
                                    </td>
                                    <td>
                                        <a href="user.html"><i class="icon-pencil"></i></a>
                                        <a href="#myModal" role="button" data-toggle="modal"><i class="icon-remove"></i></a>
                                    </td>

                                    <div style="clear: both;"></div>
                                </tr>
                                <?php
                            }
                        }else{
                            echo "<script> alert('查询失败!'); location.href='../index.php';</script>";
                        }

                    } catch (PDOException $e) {
                        echo 'Connection failed';
                    }
                    ?>

                    </tbody>
                </table>
            </div>
            <div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="myModalLabel">Delete Confirmation</h3>
                </div>
                <div class="modal-body">
                    <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete the user?</p>
                </div>
                <div class="modal-footer">
                    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
                    <button class="btn btn-danger" data-dismiss="modal">Delete</button>
                </div>
            </div>
            <footer>
                <div class="pagination">
                    <ul>
                        <li><a href="../index.php?page=1">首页</a></li>
                        <li><a href="../index.php?page=<?= ($page > 1) ? $page - 1 : 1 ?>">上一页</a></li>
                        <?php if ($total < 8) { ?>
                            <?php for ($i = 1; $i <= $total; $i++) { ?>
                                <li><a href="../index.php?page=<?= $i ?>"><?= $i ?></a></li>
                            <?php } ?>
                        <?php } else { ?>
                            <?php for ($i = 1; $i <= 1; $i++) { ?>
                                <li><a href="../index.php?page=<?= $page - $i ?>"><?= $page - $i ?></a></li>
                            <?php }
                        } ?>

                        <li><a href="../index.php?page=<?= ($page < $total) ? $page + 1 : $total ?>">下一页</a>
                        </li>
                        <li><a href="../index.php?page=<?= $total ?>">尾页</a></li>
                        <div style="clear: both;"></div>
                    </ul>
                </div>
            </footer>

        </div>
    </div>
</div>
